package ejercicio_7;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

import javax.xml.crypto.Data;

public class Actividad_7_Ej_1y2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		// Ejercicio 1 y 2

		Scanner sc = new Scanner(System.in);
		String nombreFichero = "C:\\Double.bin";
		double valor;
		// Creamos el fichero
		File f = new File(nombreFichero);

		double i;

		try {
			FileOutputStream out = new FileOutputStream(f);
			DataOutputStream outS = new DataOutputStream(out);
			// introducimos los valores al fichero y para salir pulsamos
			// CTRL+Z
			System.out.println("Introduce valores al fichero");
			while (sc.hasNext()) {

				String aux = sc.next();

				valor = Double.parseDouble(aux);

				outS.writeDouble(valor);
			}
		} catch (IOException e) {
		}

		try {
			FileInputStream in = new FileInputStream(f);
			DataInputStream inS = new DataInputStream(in);
			// Lee los valores introducidos previamente
			System.out.println("Los valores introducidos al fichero son: ");

			while ((i = inS.readDouble()) != -1) {
				System.out.println(i);
			}
		} catch (IOException e) {
		}

	}

}
